package com.eascs.spider.huangye88.util;

import java.util.HashMap;
import java.util.Map;

import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class MongodbUtil {
	
	private static Logger logger = LoggerFactory.getLogger(MongodbUtil.class);
	private static MongoClient mongoClient = null;
	private static MongoDatabase mongoDatabase = null;
	
	static{
		  // 连接到 mongodb 服务
	      mongoClient = new MongoClient( "192.168.14.131" , 27017 );
	      // 连接到数据库
	      mongoDatabase = mongoClient.getDatabase("guangdong");  
	}
	
	public static void set(String collectionName ,Map<String, Object> map){
		MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(collectionName);
		Document document = new Document(map);
		mongoCollection.insertOne(document);
	}
	
	public static void main(String[] args) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("1212", (Object)"dddddddddddddddd");
	}
	
}
